import React,{useState,useEffect} from 'react'
import { Card,  Button, Image, Form, Input } from 'antd';
import {useDispatch,useHistory,useParams} from 'umi'
const formRef = React.createRef();
export default function add() {
    const [imgSrc,setImgSrc]=useState('')
    const history=useHistory()
    const dispatch=useDispatch()
    const params=useParams()
    useEffect(()=>{
        formRef.current.setFieldsValue()
        console.log(params);
    },[])
    //表单完成新增
    const onFinish = (values) => {
        values.image_src='666'
        // values._id=params.id
        // console.log('Success:', values);
        dispatch({
            type:'bannerModule/updateBannerInit',
            payload:values
        })
      };
      //返回键
      const toBack=()=>{
        history.go(-1)
      }
    return (
        <Card title="修改轮播图" extra={<a onClick={toBack}>返回</a>} style={{ width: "98.5%" }}>
            <Form
                name="basic"
                labelCol={{
                    span: 2,
                }}
                wrapperCol={{
                    span: 6,
                }}
                ref={formRef}
                onFinish={onFinish}
                autoComplete="off"
            >
                <Form.Item
                    label="商品ID"
                    name="goods_id"
                >
                    <Input disabled/>
                </Form.Item>

                <Form.Item
                    label="图片"
                    name="image_src"
                >
                    <Image src={imgSrc} style={{width:'250px',height:'180px'}}/>
                </Form.Item>
                <Form.Item
                    label="导航地址"
                    name="navigator_url"
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="打开方式"
                    name="open_type"
                >
                    <Input />
                </Form.Item>


                <Form.Item
                    wrapperCol={{
                        offset: 2,
                        span: 6,
                    }}
                >
                    <Button type="primary" htmlType="submit">
                        确认新增
                    </Button>
                </Form.Item>
            </Form>
        </Card>
    )
}
